package com.virtualCat.dao;

import com.virtualCat.entity.Feed;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

public interface FeedDao {

    @Insert("insert into t_feed(openid,catid,feedCount,feedTime,shareCount,discover,growth) " +
            "values(#{openid},#{catid},#{feedCount},#{feedTime},#{shareCount},#{discover},#{growth})")
    int insert(Feed feed);

    @Update("update t_feed set feedCount=#{feedCount},feedTime=#{feedTime}," +
            "shareCount=#{shareCount},discover=#{discover},growth=#{growth} where openid=#{openid}")
    int updateFeed(Feed feed);

    @Update("update t_feed set growth=#{growth} where openid=#{openid}")
    int updateGrowthByOpenid(@Param("growth")int growth,@Param("openid")String openid);

    @Select("select * from t_feed")
    List<Feed> findAll();

    @Select("select openid,catid,feedCount,feedtime,shareCount,discover,growth from" +
            " t_feed where openid=#{openid}")
    @Results({
            @Result(column="feedtime",property="feedTime")}
    )
    Feed findByOpenid(@Param("openid") String openid);


    @Delete("delete from t_feed where openid=#{openid}")
    int deleteFeed(@Param("openid") String openid);

    @Select("SELECT count(1) from t_feed where openid=#{openid}")
    int checkByOpenid(@Param("openid") String openid);
}
